package common

import (
	"bytes"
	"encoding/base64"
	"fmt"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"io"
	"mime/multipart"
	"os"
)

func AliFile(file *multipart.FileHeader) string {
	client, err := oss.New("oss-cn-shanghai.aliyuncs.com", "LTAI5tC7H4HwCxeTu8C6jg4B", "fLlserGDpFdDczblLGXcjtAJGpHOe1")
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// 填写存储空间名称，例如examplebucket。
	bucket, err := client.Bucket("gwming")
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	res, _ := file.Open()
	key, _ := io.ReadAll(res)
	err = bucket.PutObject(file.Filename, bytes.NewReader(key))
	str := "高伟明"
	encoded := base64.StdEncoding.EncodeToString([]byte(str))
	fmt.Println("11111111111111111111111111111")
	fmt.Println(encoded)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	return "https://gwming.oss-cn-shanghai.aliyuncs.com/" + file.Filename + "?x-oss-process=image/watermark,text_6auY5Lyf5piO"
}
